import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:lazy_food/components/keepAliveWrapper/keep_alive_arapper.dart';
import 'package:lazy_food/home/recommend/more.dart';
import 'package:lazy_food/models/recommend_model.dart';
import 'package:lazy_food/net/network.dart';
import '../../models/tab_model.dart';

class OtherPage extends StatefulWidget {
  TabModel tab;
  OtherPage({Key? key, required this.tab}) : super(key: key);
  @override
  State<OtherPage> createState() => _OtherPageState();
}

class _OtherPageState extends State<OtherPage> {
  EasyRefreshController _refreshController =
      EasyRefreshController(controlFinishRefresh: true);
  List<RecommendFoodModel> _models = [];

  void _onRefresh() {
    EasyLoading.show();
    Network.getHomeOther(widget.tab).then((value) {
      setState(() {
        _models = value;
      });
      EasyLoading.dismiss();
      _refreshController.finishRefresh();
    });
  }

  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      onRefresh: _onRefresh,
      controller: _refreshController,
      refreshOnStart: true,
      child: KeepAliveWrapper(
        child: ListView.builder(
          itemBuilder: (context, index) {
            RecommendFoodModel model = _models[index];
            return MoreView(
              model: model,
            );
          },
          itemCount: _models.length,
        ),
      ),
    );
  }
}
